﻿@using System.Web.Mvc;
@using DNA.Mvc;
@using  DNA.Mvc.Notification;
@using DNA.Mvc.UI;
@using DNA.Mvc.jQuery;

@helper ImageTitle(string title, string desc = "", string imgPath = "", int size = 48)
    {
        var Url = new UrlHelper(Context.Request.RequestContext);
    <h1 style="margin: 0px; overflow: auto;text-shadow: 0px 2px 3px #cccccc;">
        @if (!string.IsNullOrEmpty(imgPath))
        {
            <img src="@Url.Content(imgPath)" style="float:left;width:@(size)px;height:@(size)px;margin-right:5px;" alt="" />
        }
        <span style="float:left; line-height: @(size)px;">@title</span></h1>
    
        if (!string.IsNullOrEmpty(desc))
        {
    <div style="margin-left:@(size)px;padding:0px 10px 10px 10px; font-size: 120%; font-style: italic;">
        @desc
    </div>
        }
}

@helper SectionHeader(string title, int size = 2)
    {
    <h@size class="d-section">
        <span>@title</span><hr />
    </h@size>
}

@helper PackageInfo(Package pkg)
    {
    <table>
       <tr>
          <td style="vertical-align:top;">
          <h3 style="margin-top:0px;">@GE.GetContent(pkg.Title)</h3>
               <p>@MvcHtmlString.Create(GE.GetContent(pkg.Description))</p>
          </td>
        </tr>
        <tr>
            <td>
                <table style="color: #858681;">
                    <tr>
                        <td>@HttpContext.GetGlobalResourceObject("language", "RES_AUTHOR"):
                        </td> 
                        @if (pkg.DefaultAuthor != null)
                        {
                        <td>
                       
                            @pkg.DefaultAuthor.Name
                        </td>
                        <td>@HttpContext.GetGlobalResourceObject("language", "RES_ORGANIZATION") :
                        </td>
                        <td>
                            <a class="d-link" href="@pkg.DefaultAuthor.WebSite" target="_blank">@pkg.DefaultAuthor.WebSite</a>
                        </td>
                        <td>@HttpContext.GetGlobalResourceObject("language", "RES_EMAIL") :
                        </td>
                        <td>@pkg.DefaultAuthor.Email
                        </td>
                        }
                        <td>@HttpContext.GetGlobalResourceObject("language", "RES_VERSION"):
                        </td>
                        <td>@pkg.Version
                        </td>
                        <td>@HttpContext.GetGlobalResourceObject("language", "RES_RELEASEDATE"):
                        </td>
                        <td>@pkg.Published.ToString(System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat)
                        </td>
                        <td>@HttpContext.GetGlobalResourceObject("language", "RES_LICENSES"):
                        </td>
                        <td>
                            @foreach (var lic in pkg.Licenses)
                            {
                               <a target="_blank" href="@lic.Url" >@lic.Title</a>
                            }
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
             <td>
                @foreach (var link in pkg.Links)
                {
                    <table>
                        <tr>
                            <td>@link.Title:
                            </td>
                            <td>
                                <a href="@link.Url" target="_blank">@link.Url</a>
                            </td>
                        </tr>
                    </table> 
                }
            </td>
        </tr>
    </table>
}
@helper SubscriptionLink(AjaxHelper Ajax, string token)
{
    var Url=new UrlHelper(Ajax.ViewContext.RequestContext);
    var websiteName= Ajax.ViewContext.RouteData.Values.ContainsKey("website") ? Ajax.ViewContext.RouteData.Values["website"].ToString() : "home";
    var subscribed =Notifier.IsSubscribed(token, User.Identity.Name);  
    
            <div id="_subscribeCell" style="@(subscribed ? "display:none;" : "display:block;")">
                @Ajax.Dna().Link(GE.Global("RES_SUBSCRIBE"), "javascript:void(0);").ChangeType(ButtonTypes.LinkButton).Click("_subscribe();").ImageIcons(Url.Content("~/content/images/icon_mail_16.png")).GetHtml()
            </div>
            <div id="_unsubscribeCell" style="@(!subscribed ? "display:none;" : "display:block;")">
                @Ajax.Dna().Link(GE.Global("RES_UNSUBSCRIBE"), "javascript:void(0);").ChangeType(ButtonTypes.LinkButton).Click("_subscribe();").ImageIcons(Url.Content("~/content/images/icon_mail_16.png")).GetHtml()
            </div>
            <script type="text/javascript">
               function _subscribe() {
                    $.ajax({
                    type:"POST",
                    url:"@Url.Action("Subscribe", "Syndication", new { Area = "", website = websiteName})",
                    data:{token:"@token"},
                    success:function(dat){
                        if (dat.toLowerCase()=="true") {
                            $("#_subscribeCell").hide();
                            $("#_unsubscribeCell").show();
                        }
                         else  {
                            $("#_subscribeCell").show();
                            $("#_unsubscribeCell").hide();
                        }
                     }
                    });
              }
            </script>
}